package com.woniu.adapter;

import com.woniu.outlet.dao.PurchaseDetailPoMapper;
import com.woniu.outlet.dao.PurchasePoMapper;
import com.woniu.outlet.po.PurchaseDetailPo;
import com.woniu.outlet.po.PurchaseDetailPoExample;
import com.woniu.utils.PurchaseStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class PurchaseAdapter {
    @Autowired
    private PurchaseDetailPoMapper purchaseDetailPoMapper;

    @Autowired
    private PurchasePoMapper purchasePoMapper;

    @Autowired
    @Qualifier("provider1")
    private PurchaseOpenFein purchaseOpenFein;

    public String updatePurchaseStatus(Long code){
        PurchaseDetailPoExample purchaseDetailPoExample = new PurchaseDetailPoExample();
        PurchaseDetailPoExample.Criteria criteria = purchaseDetailPoExample.createCriteria();
        criteria.andPurchaseIdEqualTo(code);
        List<PurchaseDetailPo> purchaseDetailPos = purchaseDetailPoMapper.selectByExample(purchaseDetailPoExample);
        for (PurchaseDetailPo purchaseDetailPo : purchaseDetailPos) {
            if(purchaseDetailPo.getStatus().equals("N")){
                return "采购单尚未全部入库，无法验证通过";
            }
        }

//        PurchasePo purchasePo = new PurchasePo();
//        purchasePo.setId(id.longValue());
//        purchasePo.setStatus(PurchaseStatus.WAREHOUS.getStatus());

        Long id=purchasePoMapper.getPurchaseIdByCode(code);
        purchaseOpenFein.updatePurStatusById(id,PurchaseStatus.WAREHOUS.getStatus());
        return "验证成功";
    }
}
